﻿(function ($) {

	// jquery plugin for the YouTube Video Picker
	$.fn.YouTubeVideoPicker = function () {

		// internal properties
		var $this = $(this);
		var hiddenField = $this.find("input[type='hidden']");

		reSelect();

		$this.find('.video-item').click(function () {
			$(this).toggleClass('selected');
			reSelect();
		});

		function reSelect() {
			var values = '';
			var selected = $this.find('.selected');

			selected.each(function (i) {
				values += $(this).attr('rel');
				if (i < selected.length - 1) values += ',';
			});

			hiddenField.val(values);
		}
	}

})(jQuery);